<?php
/**
 *
 */
class Yz_Action_SelectById
    extends Yz_Action_Select
{

    /**
     *  @var int ?
     */
    protected $id;

    /** SQL rows limit, not required for SelectById / by primary keys
     *  @var bool(false)
     */
    protected $limit = false;



    /************************************
     *        Public methods         *
     ************************************/

    /**
     *  @param int id > 0
     *  @return this
     */
    public function setId( $id )
    {
        debug();
        $this->id = Yz_Int::testPositive($id);

        // prevent the action instance from returning results after changing parameters
        $this->executed = false;
        return $this;
    }


    /************************************
     *        Protected methods         *
     ************************************/

    /** Verify arguments before building query
     *      The argument subject to verification is `id`
     *  @return this
     */
    protected function verifyArguments()
    {
        debug();
        if (! $this->id)
            throw new Yz_Action_Exception("Required parameter 'id' not set");
        return $this;
    }


    /**
     *  Apply the arguments to the SQL statement
     *      Bind the id argument
     *  @param Yz_SQL_Statement $sql
     *  @return this
     */
    protected function applyArguments(Yz_SQL_Statement $sql)
    {
        debug();
        $sql
            ->where($this->model->getName() . ".id=:_id")
            ->bind("_id", $this->id)
        ;
        return $this;
    }


}
